package com.faf.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.faf.bean.Detail;
import com.faf.dao.DetailDao;

public class DetailDaoImpl extends BaseDaoImpl implements DetailDao
{
	public PreparedStatement ps = super.ps;
	public Connection con = super.con;
	public ResultSet rs = super.rs;
	
	public void updateProperty() {
		ps = super.ps;
		con = super.con;
		rs = super.rs;
	}

	@Override
	public List<Detail> getDetailListByorderNumber(String orderNumber)
	{
		String sql="select detailId,orderNumber,foodId,foodNumber,messageRemark from Detail where orderNumber=?";
		List<Detail> detailList = new ArrayList();
		try
		{
			executeQuery(sql,orderNumber);
			updateProperty();
			while(rs.next()) {
				Detail detail = new Detail(rs.getInt("detailId"),rs.getString("orderNumber"),rs.getInt("foodId"),
						rs.getInt("foodNumber"),rs.getString("messageRemark"));
				detailList.add(detail);
				
			}
		} catch (SQLException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			close();
			super.con = null;
		}
		return detailList;
	}

	@Override
	public boolean insert(Detail detail) {
		// TODO Auto-generated method stub
		String str_sql = "insert into detail (orderNumber, foodId, foodNumber, messageRemark) values(?,?,?,?)";
		
		try {
			this.executeUpdate(str_sql, 
					detail.getOrderNumber(),
					detail.getFoodId(),
					detail.getFoodNumber(),
					detail.getMessageRemark());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
		return true;
	}
	

}
